using Indiefreaks.Xna.Input;
using Indiefreaks.Xna.Sessions;
using Microsoft.Xna.Framework;

namespace Indiefreaks.Xna.Logic
{
    /// <summary>
    /// The PlayerAgent is an Agent that can react to Player Input.
    /// </summary>
    /// <remarks>You can have multiple PlayerAgents per player.</remarks>
    public class PlayerAgent : Agent
    {
        /// <summary>
        /// Returns the IdentifiedPlayer controlling this PlayerAgent
        /// </summary>
        public IdentifiedPlayer IdentifiedPlayer { get; internal set; }

        /// <summary>
        /// Returns the current PlayerAgent PlayerInput instance
        /// </summary>
        /// <remarks>If the PlayerAgent isn't local, it returns null</remarks>
        public PlayerInput Input
        {
            get { return IdentifiedPlayer.Input; }
        }

        /// <summary>
        /// Returns if the current PlayerAgent is Local to the machine or remote
        /// </summary>
        public bool IsLocal
        {
            get { return IdentifiedPlayer.Input != null; }
        }

        #region Overrides of Agent

        protected internal override void Process(GameTime gameTime)
        {
            if (IsLocal)
            {
                var elapsed = (float) gameTime.ElapsedGameTime.TotalSeconds;
                // we loop through the PlayerAgent Behaviors
                foreach (Behavior behavior in BehaviorsCollection)
                {
                    ((IProcess)behavior).Process(elapsed);
                }
            }
        }

        #endregion
    }
}